package com.ant.storage.controller;

import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.UserInfoDto;
import com.ant.storage.pojo.User;
import com.ant.storage.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/login")
@Api(tags = "登录接口")
public class LoginController {

    @Autowired
    IUserService userService;


    @ApiOperation(value = "电脑登录")
    @PostMapping()
    public ResultVo login(@RequestBody UserInfoDto dto) throws Exception {
        // 1. 校验用户名密码（实际业务中需查询数据库）
        User user1 = userService.selectUserPwd(dto.getUsername(), dto.getPassword());
        boolean empty = ObjectUtils.isEmpty(user1);
        if (empty) {
            return ResultVo.fail("用户名或密码错误");
        }
//        StpUtil.login(user1.getId());
//        // 获取生成的 Token
//        String token = StpUtil.getTokenValue();
        String token ="123131";
        return ResultVo.success("登录成功", token);
    }

//    @GetMapping("/user/info")
//    public String getUserInfo() {
//        return "当前登录用户ID：" + StpUtil.getLoginId();
//    }

    /**
     * 退出登录接口（需登录才能访问）
     */
//    @PostMapping("/logout")
//    public ResultVo  logout() {
//        StpUtil.logout(); // 销毁 Token 及会话
//        return ResultVo.success("请求成功");
//    }
}
